<template>
  <div>
    <template v-if="linkMode=='deal'">
      <!-- query:{id:form.dealId,companyId:form.companyId}} -->
      <template v-if="view">
        <router-link
          target="_blank"
          :to="{path:'/deal/home/dealBaseHome',query:{id:form.dealId,companyId:form.companyId}}"
          class="link_a"
        >{{ form.name }}
        </router-link>
      </template>
      <template v-else>
        <span v-html="form.name" />
      </template>
    </template>
    <template v-else-if="linkMode=='company'">
      <!-- query:{companyId:form.companyId}} -->
      <template v-if="view">
        <router-link
          target="_blank"
          :to="{path:'/company/base/companyBaseHome',query:{companyId:form.companyId}}"
          class="link_a"
        >{{ form.name }}
        </router-link>
      </template>
      <template v-else>
        <span v-html="form.name" />
      </template>
    </template>
    <template v-else-if="linkMode=='fund'">
      <!-- query:{id:form.fundId}} -->
      <template v-if="view">
        <router-link
          target="_blank"
          :to="{path:'/fund/fundBasehome',query:{id:form.fundId}}"
          class="link_a"
        >{{ form.name }}
        </router-link>
      </template>
      <template v-else>
        <span v-html="form.name" />
      </template>
    </template>
  </div>
</template>

<script>
import { queryNameByType } from '@/api/system/desform/onlineForm/onlCgformHead'
export default {
  name: 'LinkModel',
  props: {
    // 可配置值 项目 deal、基金 fund、公司 company
    linkMode: {
      type: String,
      required: false,
      default: () => 'deal'
    },
    value: {
      type: String,
      default: '',
      desc: 'id'
    },
    view: {
      type: Boolean,
      default: true
    }
   },
   data() {
   return {
      form: {},
     companyId: this.$route.query.companyId,
     dataId: this.$route.query.id

     }
   },

  watch: {
    value: {
      handler(value) {
        if (value) {
          if (!this.form.name) {
            this.getDefaultV(value)
          }
        }
      },
      deep: true,
      immediate: true
    }
  },
  created() {
    this.getDefaultV()
    console.log(this.value)
   },
    methods: {
      getDefaultV(value) {
          var dataId = this.dataId
          if (this.linkMode === 'company') {
            dataId = this.companyId
          }
          if (value) {
            dataId = value
          }
          queryNameByType(this.linkMode, dataId).then(response => {
            this.form = response.data
          })
      }
   }

}
</script>

<style>

</style>
